﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LoghogInterface
{
    /// <summary>
    /// Логика взаимодействия для ColumnsDispleyIndex.xaml
    /// </summary>
    public partial class ColumnsDispleyIndex : Window
    {
        private MainWindow parent;
        public void SetParent(MainWindow url)
        {
            parent = url;
        }

        private ColumnsIndex WorkInd;

        public ColumnsDispleyIndex()
        {
            InitializeComponent();

        }

        private void bUp_Click(object sender, RoutedEventArgs e)
        {
            WorkInd.Up(listBox1.SelectedIndex);
            if (listBox1.SelectedIndex == 0) { bUp.IsEnabled = false; bDown.IsEnabled = true; }
            else { bUp.IsEnabled = true; bDown.IsEnabled = true; }
        }

        private void bDown_Click(object sender, RoutedEventArgs e)
        {
            WorkInd.Down(listBox1.SelectedIndex);
            if (listBox1.SelectedIndex == 4) { bUp.IsEnabled = true; bDown.IsEnabled = false; }
            else { bUp.IsEnabled = true; bDown.IsEnabled = true; }
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listBox1.SelectedIndex == 0) { bUp.IsEnabled = false; bDown.IsEnabled = true; }
            else if (listBox1.SelectedIndex == 4) { bDown.IsEnabled = false; bUp.IsEnabled = true; }
            else { bDown.IsEnabled = true; bUp.IsEnabled = true; }
        }

        private void bCansel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void bOK_Click(object sender, RoutedEventArgs e)
        {
            parent.Ind = WorkInd;
            for (int i = 0; i < 5; i++)
            {
                parent.dataGrid1.Columns[parent.Ind[i].Id].DisplayIndex = i;
            }
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WorkInd = new ColumnsIndex(parent.Ind);
            listBox1.ItemsSource = WorkInd;
        }
    }
}
